﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel.Design;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using Liquid.Windows.Commands;

namespace Liquid.Windows.Design.Commands {
	internal class CommandSetDesigner : ComponentDesigner<CommandSet> {
		public override void Initialize(CommandSet component) {
			base.Initialize(component);

			var host = (IDesignerHost)GetService(typeof(IDesignerHost));
			var changeService = (IComponentChangeService)host.GetService(typeof(IComponentChangeService));
			changeService.ComponentAdded += new ComponentEventHandler(changeService_ComponentAdded);
			changeService.ComponentRemoved += new ComponentEventHandler(changeService_ComponentRemoved);
		}

		void changeService_ComponentAdded(object sender, ComponentEventArgs e) {
			if (Component != null)
				if (e.Component is Command) {
					var command = (Command)e.Component;
					if (!Component.Commands.Contains(command))
						Component.Commands.Add(command);
				}
		}
		void changeService_ComponentRemoved(object sender, ComponentEventArgs e) {
			if (Component != null)
				if (e.Component is Command) {
					var command = (Command)e.Component;
					Component.Commands.Remove(command);
				}
		}
	}
}
